package com.huawei.hwid.core.a;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.d.d;
import com.huawei.hwid.core.d.n;
import java.util.LinkedList;
import java.util.Queue;

public final class a {
    private static final String a = n.c();
    private static volatile a b;
    private String c;
    private String d;
    private Queue<b> e = new LinkedList();
    private Queue<b> f = new LinkedList();

    private a(Context context) {
        this.c = b(context);
        if (TextUtils.isEmpty(this.d)) {
            this.d = c(context);
        }
    }

    public static a a(Context context) {
        if (b == null) {
            synchronized (a.class) {
                if (b == null) {
                    b = new a(context);
                }
            }
        }
        return b;
    }

    public void a(String str) {
        this.d = str;
    }

    public synchronized void a(b bVar) {
        if (this.e.offer(bVar) && this.e.size() > 10) {
            this.e.remove();
        }
    }

    public synchronized void b(b bVar) {
        if (this.f.offer(bVar) && this.f.size() > 10) {
            this.f.remove();
        }
    }

    public synchronized void a() {
        this.e.clear();
    }

    public synchronized Queue<b> b() {
        return this.e;
    }

    public synchronized Queue<b> c() {
        return this.f;
    }

    public synchronized void d() {
        for (b a : this.f) {
            a(a);
        }
        this.f.clear();
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public java.lang.String toString() {
        /*
        r7 = this;
        r6 = 1;
        r1 = new java.io.ByteArrayOutputStream;
        r1.<init>();
        r2 = com.huawei.hwid.core.d.p.a(r1);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = "UTF-8";
        r3 = 1;
        r3 = java.lang.Boolean.valueOf(r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r2.startDocument(r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = 0;
        r3 = "OpLogReq";
        r2.startTag(r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = "clientVer";
        r3 = r7.c;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        com.huawei.hwid.core.d.p.a(r2, r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = "osVersion";
        r3 = a;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        com.huawei.hwid.core.d.p.a(r2, r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = "channel";
        r3 = r7.d;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        com.huawei.hwid.core.d.p.a(r2, r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = r7.e;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        if (r0 == 0) goto L_0x007b;
    L_0x0033:
        r0 = r7.e;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = r0.size();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r3 = 0;
        r4 = "logList";
        r3 = r2.startTag(r3, r4);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r4 = 0;
        r5 = "size";
        r0 = java.lang.String.valueOf(r0);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r3.attribute(r4, r5, r0);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = r7.e;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r3 = r0.iterator();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
    L_0x0050:
        r0 = r3.hasNext();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        if (r0 == 0) goto L_0x0075;
    L_0x0056:
        r0 = r3.next();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = (com.huawei.hwid.core.a.b) r0;	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r4 = "Log";
        r0 = r0.toString();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        com.huawei.hwid.core.d.p.a(r2, r4, r0);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        goto L_0x0050;
    L_0x0066:
        r0 = move-exception;
        r0 = "OpLogInfo";
        r2 = "IllegalArgumentException";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ all -> 0x010a }
        r0 = "";
        r1.close();	 Catch:{ IOException -> 0x009f }
    L_0x0074:
        return r0;
    L_0x0075:
        r0 = 0;
        r3 = "logList";
        r2.endTag(r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
    L_0x007b:
        r0 = 0;
        r3 = "OpLogReq";
        r2.endTag(r0, r3);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r2.endDocument();	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r0 = "UTF-8";
        r0 = r1.toString(r0);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r2 = "OpLogInfo";
        r3 = "packedString";
        r4 = 1;
        com.huawei.hwid.core.d.b.e.b(r2, r3, r4);	 Catch:{ IllegalArgumentException -> 0x0066, IllegalStateException -> 0x00a8, IOException -> 0x00c0, RuntimeException -> 0x00d8, Exception -> 0x00f0 }
        r1.close();	 Catch:{ IOException -> 0x0096 }
        goto L_0x0074;
    L_0x0096:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x009f:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x00a8:
        r0 = move-exception;
        r0 = "OpLogInfo";
        r2 = "IllegalStateException";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ all -> 0x010a }
        r0 = "";
        r1.close();	 Catch:{ IOException -> 0x00b7 }
        goto L_0x0074;
    L_0x00b7:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x00c0:
        r0 = move-exception;
        r0 = "OpLogInfo";
        r2 = "IOException";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ all -> 0x010a }
        r0 = "";
        r1.close();	 Catch:{ IOException -> 0x00cf }
        goto L_0x0074;
    L_0x00cf:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x00d8:
        r0 = move-exception;
        r0 = "OpLogInfo";
        r2 = "RuntimeException";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ all -> 0x010a }
        r0 = "";
        r1.close();	 Catch:{ IOException -> 0x00e7 }
        goto L_0x0074;
    L_0x00e7:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x00f0:
        r0 = move-exception;
        r0 = "OpLogInfo";
        r2 = "Exception";
        r3 = 1;
        com.huawei.hwid.core.d.b.e.d(r0, r2, r3);	 Catch:{ all -> 0x010a }
        r0 = "";
        r1.close();	 Catch:{ IOException -> 0x0100 }
        goto L_0x0074;
    L_0x0100:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x0074;
    L_0x010a:
        r0 = move-exception;
        r1.close();	 Catch:{ IOException -> 0x010f }
    L_0x010e:
        throw r0;
    L_0x010f:
        r1 = move-exception;
        r1 = "OpLogInfo";
        r2 = "IOException";
        com.huawei.hwid.core.d.b.e.d(r1, r2, r6);
        goto L_0x010e;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwid.core.a.a.toString():java.lang.String");
    }

    private String b(Context context) {
        PackageManager packageManager = context.getPackageManager();
        String str = "";
        if ("com.huawei.hwid".equals(context.getPackageName())) {
            try {
                str = packageManager.getPackageInfo(context.getPackageName(), 0).versionName;
            } catch (NameNotFoundException e) {
                e.d("OpLogInfo", "NameNotFoundException", true);
            }
            return "HwID " + str;
        }
        return "SDK " + HwAccountConstants.SDK_VERSION;
    }

    private String c(Context context) {
        String str = "";
        if (d.b()) {
            return HwAccountConstants.OOBE_CHANNEL;
        }
        return com.huawei.hwid.core.d.a.a(context, d.c());
    }
}
